<!DOCTYPE html>
<html lang="zh-cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body>
<form id="form" class="layui-form-pane layui-form">
    <input type="hidden" id="id" name="id" th:value="${announcement.getId()}">
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">标题：</label>
        <div class="layui-input-block">
            <input class="layui-input" id="title" name="title" th:value="${announcement.getTitle()}" autocomplete="off"/>
        </div>
    </div>
    <br/>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">内容：</label>
        <div class="layui-input-block">
            <textarea class="layui-textarea" id="content" name="content"   autocomplete="off">[[${announcement.getContent()}]]</textarea>
        </div>
    </div>
    <br/>
    <div class="layui-form-item layui-inline" style="float: right; margin-right: 10px;">
        <button class="layui-btn" type="button" id="updateAnnouncement">提交</button>
        <button class="layui-btn layui-btn-danger" onclick="closePage()">关闭</button>
    </div>

</form>

</body>
<script th:src="@{/js/jquery-2.1.0.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script>
    var index = parent.layer.getFrameIndex(window.name);
    layui.use('form',function(){
        var form = layui.form;
        form.render();
    });
    layui.use('layer',function(){
        var layer=layui.layer;
    });
    function closePage() {
        parent.layer.close(index);//关闭当前页
    }

    $('#updateAnnouncement').click(function(){
        var content = $("#content").val();
        var title = $("#title").val();
        if (title == ""){
            layui.use('layer',function(){
                layer=layui.layer;
                layer.msg('标题不能为空',{
                    icon:0
                });
            });
        }else if (content == ""){
            layui.use('layer',function(){
                layer=layui.layer;
                layer.msg('内容不能为空',{
                    icon:0
                });
            });
        }else {
            $.ajax({
                type:'post',
                url:'/announcement/updateAnnouncement',
                data:$("#form").serialize(),
                dataType: "text",
                async: false,
                success:function (data) {
                    if (data === 1){
                    }
                }
            });
            window.parent.location.reload();//刷新父页面
            parent.layer.close(index);
        }
        return
    });

</script>
</html>